Hi! I have to list all outgoing and incoming linked modules in the following way: Out-Links Module Name 1, Baseline 10,2 Module Name 2, Baseline 4,1
In-Links Module Name 3, Baseline 1,2 Module Name 4, Baseline 3,4 Module Name 5, Baseline 5,6
I wrote a script that opens the links and iterate all objects, can s.o. give me an example how to do this more efficiently?
string getTraceabilityForModule(Module m)
{
Object obj;
Skip inLinkSkip=createString;
Skip outLinkSkip=createString;
filtering off;
for obj in m do
{
Link lnk;
for lnk in obj->"*" do
{
string tmn=fullName target(lnk);
Module openMod=read(tmn,false);
Baseline b = getMostRecentBaseline(openMod);
int majorBL=-1;
int minorBL=-1;
if(null b)
{
majorBL=0;
minorBL=0;
}
else
{
majorBL=major b;
minorBL=minor b;
}
outLinks=tmn ", Baseline " majorBL "." minorBL "";
string dummy;
if(!find(outLinkSkip, outLinks, dummy))
{
put(outLinkSkip, outLinks, outLinks);
}
}
//print outLinks;
LinkRef lnkRef;
ModName_ otherMod = null;
for lnkRef in all(obj<-"*") do
{
otherMod = module (sourceVersion lnkRef);
if (!null otherMod)
{
if ((!isDeleted otherMod) && (null data(sourceVersion lnkRef)))
{
load((sourceVersion lnkRef),false);
}
}
}
for lnk in obj <- "*" do
{
Object src = source lnk;
Baseline b = getMostRecentBaseline(module src);
int majorBL=-1;
int minorBL=-1;
if(null b)
{
majorBL=0;
minorBL=0;
}
else
{
majorBL=major b;
minorBL=minor b;
}
inLinks=fullName(module src) ", Baseline " majorBL "." minorBL "";
string dummy2;
if(!find(inLinkSkip, inLinks, dummy2))
{
put(inLinkSkip, inLinks, inLinks);
}
}
}
string gesamtAusgabe="";
bool isFirst=true;
bool hasOutLinks=false;
for myIterator in outLinkSkip do
{
string myKey = (string key(outLinkSkip));
string myValue = "";
if(find(outLinkSkip , myKey, myValue))
{
if(isFirst)
{
gesamtAusgabe=gesamtAusgabe "{\\b Out-Links }" ;
isFirst=false;
}
gesamtAusgabe=gesamtAusgabe "\n" myKey;
hasOutLinks=true;
}
}
// Ne Zeile zwischen machen
if(hasOutLinks)
{
gesamtAusgabe=gesamtAusgabe "\n\n";
}
isFirst=true;
for myIterator in inLinkSkip do
{
string myKey = (string key(inLinkSkip));
string myValue = "";
if(find(inLinkSkip , myKey, myValue))
{
if(isFirst)
{
gesamtAusgabe=gesamtAusgabe "{\\b In-Links }" ;
isFirst=false;
}
gesamtAusgabe=gesamtAusgabe "\n" myKey
}
}
delete outLinkSkip;
delete inLinkSkip;
return gesamtAusgabe;
}
print getTraceabilityForModule(current);
Bjoern_Karpenstein - Tue Dec 15 09:37:46 EST 2015 |
Re: Get all outgoing and incoming linked modules + Baseline Version I would think, that you only need to iterate through the links only once. You also do not need to open the target modules, if you only need to get the baseline version. I also would think, that you should first count, then later generate the messages.
Just pseudo code:
// sk is a counting skip. KEY = version (string), value = counter (int)
// increases the count inside the skip for the key 'sKey' by the value 'increment'
void increaseCount(Skip sk, string sKey, int increment) {
int count = 0;
find (sk, sKey, count);
count += increment;
put(sk, sKey, count, true); // overwrite old value key
}
for L in o->"*" do {
string version = versionString targetVersion L
increaseCount(skCountOut, version, 1);
}
for LR in o<-"*" do {
string version = versionString sourceVersion LR
increaseCount(skCountOut, version, 1);
}
Maybe it can be of some help. Regards, Mathias |
Re: Get all outgoing and incoming linked modules + Baseline Version Provided I understand correctly that you want to list latest baseline of linked modules and that you in fact are not interested in counting links something like below could possibly help. A problem with your initial code is that you potentially do the same thing over and over within the "for obj..." loop. Moreover, building a string like that is not advisable due to how DXL handles strings.
void collectBaselineInfo(Buffer buf, Skip skp)
{
Module m
Baseline b
ModName_ mn
for mn in skp do
{
m = read(fullName mn, false)
if ( !null m )
{
buf += name(mn)
b = getMostRecentBaseline(m);
if ( !null b )
{
buf += ( ", Baseline " major(b) "." minor(b) "\n")
}
else
{
buf += ", Baseline 0.0\n"
}
}
close m
}
}
string getTraceability(Module m)
{
Object o
Link l
ModName_ mn
Skip targetSkp = create
Skip sourceSkp = create
Buffer buf = create
// Collect targetmodules and sourcemodules
for o in m do
{
for l in o -> "*" do
{
mn = target l
put(targetSkp, mn, mn)
}
for mn in o <- "*" do
{
put(sourceSkp, mn, mn)
}
}
buf += "Out-Links\n"
collectBaselineInfo(buf, targetSkp)
buf += "\nIn-Links\n"
collectBaselineInfo(buf, sourceSkp)
string s = stringOf buf
delete buf
return s
}
Module m = current
print getTraceability(m)
|
Re: Get all outgoing and incoming linked modules + Baseline Version morast - Wed Dec 16 08:43:07 EST 2015 Provided I understand correctly that you want to list latest baseline of linked modules and that you in fact are not interested in counting links something like below could possibly help. A problem with your initial code is that you potentially do the same thing over and over within the "for obj..." loop. Moreover, building a string like that is not advisable due to how DXL handles strings.
void collectBaselineInfo(Buffer buf, Skip skp)
{
Module m
Baseline b
ModName_ mn
for mn in skp do
{
m = read(fullName mn, false)
if ( !null m )
{
buf += name(mn)
b = getMostRecentBaseline(m);
if ( !null b )
{
buf += ( ", Baseline " major(b) "." minor(b) "\n")
}
else
{
buf += ", Baseline 0.0\n"
}
}
close m
}
}
string getTraceability(Module m)
{
Object o
Link l
ModName_ mn
Skip targetSkp = create
Skip sourceSkp = create
Buffer buf = create
// Collect targetmodules and sourcemodules
for o in m do
{
for l in o -> "*" do
{
mn = target l
put(targetSkp, mn, mn)
}
for mn in o <- "*" do
{
put(sourceSkp, mn, mn)
}
}
buf += "Out-Links\n"
collectBaselineInfo(buf, targetSkp)
buf += "\nIn-Links\n"
collectBaselineInfo(buf, sourceSkp)
string s = stringOf buf
delete buf
return s
}
Module m = current
print getTraceability(m)
Hi thank you vey much. Is there another way iterating over link modules it get it more faster? My problem is that I cannot fetch the Baseline Info
string nSatisfiesLinkModule = "/NDS/90 Administration/Satisfies";
Object o = null;
string src = "";
string tgt = "";
SatisfiesLinkModule = read(nSatisfiesLinkModule, false);
for o in SatisfiesLinkModule do
{
// get names of source and target modules
src = o."source" "";
tgt = o."target" "";
Item srcItem=item(src);
Item tgtItem=item(tgt);
if(!null srcItem&&!null tgtItem)
{
if(type srcItem "" == "Formal")
{
Module srcMod=module srcItem;
print fullName(srcMod) "";
}
print " -> ";
if(type tgtItem"" == "Formal")
{
Module tgtMod=module srcItem;
print fullName(tgtMod) "\n";
}
}
}
|
Re: Get all outgoing and incoming linked modules + Baseline Version Bjoern_Karpenstein - Fri Jan 15 05:15:16 EST 2016
Hi thank you vey much. Is there another way iterating over link modules it get it more faster? My problem is that I cannot fetch the Baseline Info
string nSatisfiesLinkModule = "/NDS/90 Administration/Satisfies";
Object o = null;
string src = "";
string tgt = "";
SatisfiesLinkModule = read(nSatisfiesLinkModule, false);
for o in SatisfiesLinkModule do
{
// get names of source and target modules
src = o."source" "";
tgt = o."target" "";
Item srcItem=item(src);
Item tgtItem=item(tgt);
if(!null srcItem&&!null tgtItem)
{
if(type srcItem "" == "Formal")
{
Module srcMod=module srcItem;
print fullName(srcMod) "";
}
print " -> ";
if(type tgtItem"" == "Formal")
{
Module tgtMod=module srcItem;
print fullName(tgtMod) "\n";
}
}
}
To get the desired baseline info you need to open the formal modules. Moreover you have a problem when trying to get a handle of the modules: Module srcMod = module srcItem // This will ONLY work if the module is already open! Also, you should be aware that looping linksets stored in a link module is not the same thing as looping actual links in a formal module. |
Re: Get all outgoing and incoming linked modules + Baseline Version Hi morast. Thank you for your reply. Can you tell me what especially is the difference between 1.) getting all connections via link module and 2.) getting all connections via formal module? I only know that link modules only can be used to iterate current versions. By the way i am still wondering what happens with Baseline-Links when a link module has been deleted (do they still have the same type?)
With best regards, |
Re: Get all outgoing and incoming linked modules + Baseline Version Bjoern_Karpenstein - Tue Jan 19 03:26:02 EST 2016 Hi morast. Thank you for your reply. Can you tell me what especially is the difference between 1.) getting all connections via link module and 2.) getting all connections via formal module? I only know that link modules only can be used to iterate current versions. By the way i am still wondering what happens with Baseline-Links when a link module has been deleted (do they still have the same type?)
With best regards, Well, looping through a link module will provide you with the inksets stored in that link module. In principle a linkset is a pair of modules: a source module and a target module. If you are interested in link relations of a particular formal module you have to check if that formal module matches the source module of the linkset, the target module of the linkset, both or neither. However linksets can be stored in more than one link module. So in the general case, looping through a specific link module (like in your code) will not catch all link relations. Another thing is that you can create a linkset before creating any actual links. So you may have "empty" linksets. Looping through actual links will not catch target module or source modules of "empty" linksets. If that's desired behaviour or not is up to you. |